import { defineConfig } from 'vite'
import path from 'path'
import uni from '@dcloudio/vite-plugin-uni'
import AutoImport from 'unplugin-auto-import/vite'

const __dirname = new URL('.', import.meta.url).pathname
const host = 'http://10.101.20.52:9010'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [uni(), AutoImport({
        imports: ['vue', 'uni-app', 'pinia'],
        dts: true
    })],
    css: {
        preprocessorOptions: {
            scss: {
                // 取消sass废弃API的报警
                silenceDeprecations: [
                    'legacy-js-api',
                    'color-functions',
                    'import'
                ]
                // additionalData: '@import "@/static/styles/index.scss";'
            }
        }
    },
    resolve: {
        alias: {
            '@': path.resolve(__dirname, './src'),
            '@images': path.resolve(__dirname, './src/static/images'),
            '@styles': path.resolve(__dirname, './src/static/styles')
        }
    },
    base: '/h5/',
    server: {
        port: 3001,
        strictPort: false, // 端口被占用vite会退出
        cors: true, // 为开发服务器配置CORS，默认启用并允许任何源
        open: false, // 是否自动打开浏览器
        // 反向代理 跨域配置
        proxy: {
            '/api': {
                target: host,
                changeOrigin: true,
                secure: false
            }
        }
    },
    build: {
        target: 'esnext', // 或者 'es2017', 'es2018' 等，取决于你的需求
        rollupOptions: {
            output: {
                format: 'es' // 确保这里不是 'cjs' 或 'umd' 等
            }
        }
    }
})
